function getGeetest({loginname, mark}){
    return new Promise(function(resolve, reject){
        $.ajax({
            url: baseUrl + "/bdc/api/app/login/geetest",
            type: "get",
            data: {
                loginname: loginname,
                mark: mark
            },
            dataType: "json",
            success: function (res) {
                
                var data = res.data
                // challenge: "fdca5322e748cbb3c82b1a0cdb0b5bc8"
                // gt: "4199cf071104b580b71936996fbbb072"
                // success: 1

                function handlerGeetest(obj){
                    window.captchaObj = obj
                    captchaObj.appendTo("#validCode");
                    captchaObj.onReady(function () {
                        captchaObj.verify()
                        layer.close(loadding)
                    });
                    captchaObj.onError(function (error) {
                        captchaObj.reset()
                    });
                    captchaObj.onSuccess(function () {
                        
                        resolve()
                    })
                }

                // 调用 initGeetest 初始化参数
                // 参数1：配置参数
                // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它调用相应的接口
                initGeetest({
                    gt: data.gt,
                    challenge: data.challenge,
                    // new_captcha: data.new_captcha, // 用于宕机时表示是新验证码的宕机
                    // offline: !data.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                    product: "bind", // 产品形式，包括：float，popup
                    width: "100%"
                }, handlerGeetest);
            }
        });
    })
    
}

function getSmsCode({phone, mark, typeCode}){
    return new Promise((resolve, reject) => {
        var result = captchaObj.getValidate();
        loadding = layer.open({type: 2});
        $.ajax({
            url: baseUrl + "/bdc/api/app/checkcode/jY",
            type: "post",
          
            data:{
                phone: phone,
                typeCode: typeCode,
                mark: mark,
                geetest_challenge: result.geetest_challenge,
                geetest_seccode: result.geetest_seccode,
                geetest_validate: result.geetest_validate
            },
            xhrFields: {
    　　　　　　withCredentials: true
    　　　　},
            crossDomain: true,
            dataType: "json",
            success: function (res) { 
                layer.close(loadding)
                
                resolve(res)
            },
            error: function (err) {
                var res = err.responseJSON
               
                layer.open({
                    content: res.error.message
                    ,skin: 'msg'
                    ,time: 2
                });
                layer.close(loadding)
                reject()
            }
        });
    })
}